package com.endbd.purchase.manage.brand.control;

import com.endbd.feignapi.model.purchase.CBrand;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.purchase.manage.brand.model.BrandCondition;
import com.endbd.purchase.manage.brand.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/purchase")
@RestController
public class BrandAction {

    @Autowired
    private IBrandService brandService;

    @RequestMapping("/brandPage")
    public ResultMessage BrandPage(PageModel<CBrand> pageModel, BrandCondition bcon){
        System.out.println("bcon:"+bcon);
        PageModel<CBrand> brandPageModel = brandService.queryBrandPageByCondition(pageModel,bcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setResultData(brandPageModel);
        return msg;
    }


    @RequestMapping("/brandName")
    public ResultMessage TypeName(BrandCondition bcon){
        List<String> brandName = brandService.querybrandName(bcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setResultData(brandName);
        return msg;
    }
    @RequestMapping("/addBrand")
    public ResultMessage addBrand(CBrand brand){
        brandService.addBrand(brand);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("添加了"+brand.getBrandName()+"品牌");
        return msg;

    }

    @RequestMapping("lorBrand")
    public ResultMessage lorBrand(BrandCondition bcon){
        brandService.lorBrandById(bcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        if (bcon.getBrandStatus()==1){
            msg.setMsg("禁用了"+bcon.getBrandName()+"品牌");
        }else {
            msg.setMsg("恢复了"+bcon.getBrandName()+"品牌");
        }
        return msg;

    }

    @RequestMapping("alterBrand")
    public ResultMessage alterBrand(CBrand brand){
        brandService.updateBrandById(brand);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("修改为"+brand.getBrandName()+"品牌");
        return msg;
    }

    @RequestMapping("/brandType")
    public ResultMessage brandType(){
        Map<String, List<String>> map = brandService.brandType();
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(map);
        return msg;
    }

}
